package builder;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import uk.ac.ebi.kraken.interfaces.uniprot.UniProtEntry;
import uk.ac.ebi.kraken.uuw.services.remoting.EntryRetrievalService;
import uk.ac.ebi.kraken.uuw.services.remoting.UniProtJAPI;

/**
 * Servlet implementation class FileCounter
 */
public class DatasetBuilder extends HttpServlet {
	private static final long serialVersionUID = 1L;

	EntryRetrievalService entryRetrievalService = null;
	public void init() throws ServletException {
		//Create entry retrival service
	    entryRetrievalService = UniProtJAPI.factory.getEntryRetrievalService();
	}
	
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// Set a cookie for the user, so that the counter does not increate
		// everytime the user press refresh
		HttpSession session = request.getSession(true);
		// Set the session valid for 5 secs
		session.setMaxInactiveInterval(5);
		response.setContentType("text/plain");
		PrintWriter out = response.getWriter();
		
		//Create entry retrival service
	    EntryRetrievalService entryRetrievalService = UniProtJAPI.factory.getEntryRetrievalService();

	    //Retrieve UniProt entry by its accession number
	    UniProtEntry entry = (UniProtEntry) entryRetrievalService.getUniProtEntry("Q96AZ6");

	    //If entry with a given accession number is not found, entry will be equal null
	    if (entry != null) {
	      System.out.println("entry = " + entry.getUniProtId().getValue());
	    }    

	    
	    
		out.println("Hi");
	}

	public void destroy() {
		super.destroy();
	}

}

